<?php

/**
 * @author Rizky Tahara Shita
 * @website http://tahara.web.id
 * @email rizky.tahara@gmail.com
 * @copyright b'IT Cyber Solution
 */

class M_menu extends BZ_Model
{
/*
	public $menu_structure_combo;
*/
	public $breadcrumb;

	function __construct()
	{
		parent::__construct();

/*
		$this->menu_structure_combo = '';
*/
		$this->breadcrumb = array();
	}



/**
 * @section biskitz Menu Model
 */

	/**
	 * @function _list()
	 * @description the menu list
	 */
	function _list($prm_dbase = 'db_default', $prm_user_id = '', $prm_user_menu_module_use, $prm_module_id = 1, $prm_parent_id = 0, $prm_icon_use = TRUE, $prm_return_as_array = FALSE, $prm_as_access_rights = FALSE, $prm_as_access_rights_checkbox_attr = array(), $prm_as_access_rights_via_ajax = FALSE, $prm_shows_type = 'Hide')
	{
		$use_db = $this->{$prm_dbase};

		$menu_structure = array();

		$sql = 'select c.modules__id as modules_id, c.id as menu_id, d.name as name, d.title as title, link, icon, target, parent_id'
			. ' from bz_biskitz_modules a, bz_biskitz_menus c, bz_biskitz_menus_lang d';
			if (trim($prm_user_id) != '') $sql .= ', bz_biskitz_user_access b';

		$sql .= ' where a.id = c.modules__id'
			. ' and c.modules__id = d.modules__id and c.id = d.menus__id'
			. ' and d.language__id = ? and status = ? and c.modules__id = ? and parent_id = ? and shows';
			($prm_shows_type == 'Show' OR $prm_shows_type == 'Dropdown') ? $sql .= '= ?' : $sql .= '!= ?';
			if (trim($prm_user_id) != '') $sql .= ' and c.modules__id = b.modules__id and c.id = b.menus__id and biskitz_user__id = ? and type = ?';
		$sql .= ' order by c.orders';

		$qry = $use_db->query
			(
				$sql
				, array
					(
						$this->session->userdata('session_user_language_id')
						, 'Active'
						, $prm_module_id
						, $prm_parent_id
						, $prm_shows_type
						, (trim($prm_user_id) != '') ? $prm_user_id : NULL
						, 'view'
					)
			);

		if ($qry->num_rows() > 0)
		{
			foreach ($qry->result() as $rows)
			{
				/**
				 * @description need image to show ?
				 */
				$menu_image = '';
				if ($prm_icon_use && $rows->icon != NULL)
				{
					$img_attr = array
						(
							'src' => site_url('themes/' . $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN'] . '/images/menu/16/' . $rows->icon)
							, 'border' => 0, 'align' => 'left'
							, 'width' => 16, 'height' => 16
						);
					$menu_image = img($img_attr, TRUE) . '&nbsp;';
				}


				/**
				 * @description check if there is any sub menu or not
				 */
				($prm_shows_type == 'Show' OR $prm_shows_type == 'Dropdown') ? $sql_shows = 'shows' : $sql_shows = 'shows !=';

				$menu_sub_count = $this->M_database->total_rows
					(
						$prm_dbase
						, 'biskitz_menus'
						, array
							(
								'modules__id' => $rows->modules_id
								, 'parent_id' => $rows->menu_id
								, $sql_shows => $prm_shows_type
							)
					);

				/**
				 * @description let's generate the menu :)
				 */
				if ($menu_sub_count > 0)
				{
					if ($prm_return_as_array == TRUE)
					{
						if ($prm_as_access_rights == TRUE)
						{
							$prm_as_access_rights_via_ajax
								? $menu_structure[] = array
									(
										'text' => $rows->name
										, 'classes' => 'folder'
										, 'children' => $this->_list($prm_dbase, $prm_user_id, $prm_user_menu_module_use, $rows->modules_id, $rows->menu_id, $prm_icon_use, $prm_return_as_array, $prm_as_access_rights, $prm_as_access_rights_checkbox_attr, $prm_as_access_rights_via_ajax, $prm_shows_type)
									)
								: $menu_structure['<span class="folder">' . $rows->name . '</span>'] = $this->_list($prm_dbase, $prm_user_id, $prm_user_menu_module_use, $rows->modules_id, $rows->menu_id, $prm_icon_use, $prm_return_as_array, $prm_as_access_rights, $prm_as_access_rights_checkbox_attr, $prm_as_access_rights_via_ajax, $prm_shows_type);
						}
						else
						{
							$menu_structure[$rows->name] = $this->_list($prm_dbase, $prm_user_id, $prm_user_menu_module_use, $rows->modules_id, $rows->menu_id, $prm_icon_use, $prm_return_as_array, $prm_as_access_rights, $prm_as_access_rights_checkbox_attr, $prm_as_access_rights_via_ajax, $prm_shows_type);
						}
					}
					else
					{
						$menu_structure[$rows->name] = anchor
							(
								'#'
								, $menu_image . $rows->name
								, array
									(
	/*
										'title' => htmlentities($rows->title)
	*/
										'onclick' => 'return false'
										, 'class' => ($prm_user_menu_module_use == 'FALSE' && $rows->parent_id == 0) ? 'menu_main' : 'menu_sub'
									)
							)
							. ul($this->_list($prm_dbase, $prm_user_id, $prm_user_menu_module_use, $rows->modules_id, $rows->menu_id, $prm_icon_use, $prm_return_as_array, $prm_as_access_rights, $prm_as_access_rights_checkbox_attr, $prm_as_access_rights_via_ajax, $prm_shows_type));
					}

				}
				else
				{
					if ($prm_return_as_array == TRUE)
					{
						if ($prm_as_access_rights == TRUE)
						{
							$menu_checkbox = '';

							if ($prm_as_access_rights_checkbox_attr['type'] == 'favorite')
							{
								$menu_checkbox_type = array
									(
										'favorite' => array
											(
												'label' => $rows->name
											)
									);

								$menu_checkbox .= '<label>'
									. form_checkbox
										(
											array
											(
												'name' => $prm_as_access_rights_checkbox_attr['name']
												, 'id' => $prm_as_access_rights_checkbox_attr['id']
												, 'value' => $rows->modules_id . ';' . $rows->menu_id . ';favorite'
											)
										)
									. $menu_checkbox_type['favorite']['label']
									. '</label>';
							}
							else
							{
								$menu_checkbox_type = array
									(
										'view' => array
											(
												'label' => $rows->name
												, 'tag_open' => ''
												, 'tag_close' => ''
											)
										, 'add' => array
											(
												'label' => $this->lang->line('fields_administration_user_access_right_add')
												, 'tag_open' => '<small>'
												, 'tag_close' => '</small>'
											)
										, 'edit' => array
											(
												'label' => $this->lang->line('fields_administration_user_access_right_edit')
												, 'tag_open' => '<small>'
												, 'tag_close' => '</small>'
											)
										, 'delete' => array
											(
												'label' => $this->lang->line('fields_administration_user_access_right_delete')
												, 'tag_open' => '<small>'
												, 'tag_close' => '</small>'
											)
									);

								foreach ($menu_checkbox_type as $menu_type => $menu_attr)
								{
									$menu_checkbox .= '<label>'
										. form_checkbox
											(
												array
												(
													'name' => $prm_as_access_rights_checkbox_attr['name']
													, 'id' => $prm_as_access_rights_checkbox_attr['id']
													, 'value' => $rows->modules_id . ';' . $rows->menu_id . ';' . $menu_type
												)
											)
										. $menu_attr['tag_open'] . $menu_attr['label'] . $menu_attr['tag_close']
										. '</label>';
								}
							}


							$prm_as_access_rights_via_ajax
								? $menu_structure[] = array('text' => $menu_checkbox, 'classes' => 'file')
								: $menu_structure[] = '<span class="file">' . $menu_checkbox . '</span>';
						}
						else
						{
							$menu_structure[$rows->modules_id . ';' . $rows->menu_id] = $menu_image . $rows->name;
						}

					}
					else
					{
						$menu_structure[$rows->name] = anchor
							(
								site_url($rows->link)
								, $menu_image . $rows->name
								, array('target' => $rows->target)
							);

					}
				}
			}
		}


		if ($prm_return_as_array == FALSE)
		{
			$menu_structure[] = '<div class="bottom"></div>';
		}


		return $menu_structure;
	}


	/**
	 * @function _breadcrumb_generate()
	 * @description generate the breadcrumb
	 */
	function _breadcrumb_generate($prm_dbase = 'db_default', $prm_module_id, $prm_menu_id, $prm_char_separate = '&raquo;')
	{
		$use_db = $this->{$prm_dbase};

		$sql = 'select a.modules__id as modules_id, a.id as menu_id, b.name as menu_name, a.parent_id as menu_parent_id'
			. ' from bz_biskitz_menus a, bz_biskitz_menus_lang b, bz_biskitz_language c'
			. ' where a.modules__id = b.modules__id and a.id = b.menus__id and b.language__id = c.id'
			. ' and c.id = ? and a.modules__id = ? and a.id = ?';
		$qry = $use_db->query
			(
				$sql
				, array
					(
						$this->session->userdata('session_user_language_id')
						, $prm_module_id
						, $prm_menu_id
					)
			);

		if ($qry->num_rows() > 0)
		{
			$this->breadcrumb[] = '&nbsp;' . $prm_char_separate . '&nbsp;' . htmlentities($qry->row()->menu_name);
			if ($qry->row()->menu_parent_id != 0)
			{
				$this->_breadcrumb_generate($prm_dbase, $qry->row()->modules_id, $qry->row()->menu_parent_id, $prm_char_separate);
			}
		}
	}


	/**
	 * @function generate()
	 * @description generate the menu
	 */
	function generate
		(
			$prm_dbase = 'db_default'
			, $prm_user_id = '', $prm_menu_module_use = 'TRUE', $prm_menu_module_id = ''
			, $prm_icon_use = TRUE, $prm_link_use = TRUE, $prm_return_as_array = FALSE
			, $prm_menu_sub_show = TRUE, $prm_language_load = ''
			, $prm_as_access_rights = FALSE, $prm_as_access_rights_checkbox_attr = array(), $prm_as_access_rights_via_ajax = FALSE
			, $prm_parent_id = 0
			, $prm_shows_type = 'Hide'
		)
	{
		$use_db = $this->{$prm_dbase};

		$sql = 'select a.id, a.name';
			if (trim($prm_user_id) != '') $sql .= ', b.type';

		$sql .= ' from bz_biskitz_modules a';
			if (trim($prm_user_id) != '') $sql .= ', bz_biskitz_user_access b';

		$sql .= ' where status = ?';
			if (trim($prm_user_id) != '') $sql .= ' and a.id = b.modules__id and biskitz_user__id = ?'; else $sql .= ' and "" = ?';
			if (trim($prm_menu_module_id) != '') $sql .= ' and a.id = ?'; else $sql .= ' and "" = ?';
			if (trim($prm_language_load) != '') $sql .= ' and back_end_lang = ?'; else $sql .= ' and "" = ?';
		$sql .= ' group by a.id order by orders';

		$qry = $use_db->query
			(
				$sql
				, array
					(
						'Active'
						, (trim($prm_user_id) != '') ? $prm_user_id : ''
						, (trim($prm_menu_module_id) != '') ? $prm_menu_module_id : ''
						, (trim($prm_language_load) != '') ? $prm_language_load : ''
					)
			);

		$menu_structure = array();
		if ($qry->num_rows() > 0)
		{
			$menu_image = '';
			if ($prm_icon_use == TRUE)
			{
				$img_attr = array
					(
						'src' => site_url('themes/' . $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN'] . '/images/menu/16/klipper_dock.png')
						, 'border' => 0, 'align' => 'left'
						, 'width' => 16, 'height' => 16
					);
				$menu_image = img($img_attr, TRUE) . '&nbsp;';
			}


			if ($prm_as_access_rights == TRUE)
			{
				$access_rights['tag_open'] = '<span class="folder">';
				$access_rights['tag_close'] = '</span>';
			}
			else
			{
				$access_rights['tag_open'] = '';
				$access_rights['tag_close'] = '';
			}


			foreach ($qry->result() as $rows)
			{
				switch ($prm_link_use)
				{
					case TRUE:
						$menu_link = anchor
							(
								'#'
								, $menu_image . $rows->name
								, array('onclick' => 'return false', 'class' => 'menu_main')
							);
						break;


					default:
						$menu_link = strtoupper($rows->name);
						break;
				}


				$access_rights['links'] = $this->_list($prm_dbase, $prm_user_id, $prm_menu_module_use, $rows->id, $prm_parent_id, $prm_icon_use, $prm_return_as_array, $prm_as_access_rights, $prm_as_access_rights_checkbox_attr, $prm_as_access_rights_via_ajax, $prm_shows_type);

				if ($prm_as_access_rights_via_ajax == TRUE)
				{
					$menu_structure[] = array
						(
							'text' => $menu_link, 'classes' => 'folder'
							, 'children' => $prm_as_access_rights
								? (
										$prm_menu_sub_show
											? $access_rights['links']
											: NULL
									)
								: NULL
						);
				}
				else
				{
					$menu_structure[$access_rights['tag_open'] . $menu_link . $access_rights['tag_close']] = $prm_menu_sub_show
						? $access_rights['links']
						: $menu_link;
				}
////////////
				//~ switch ($prm_menu_sub_show)
				//~ {
					//~ case TRUE:
						//~ if ($prm_as_access_rights == TRUE)
						//~ {
							//~ $prm_as_access_rights_via_ajax
								//~ ? $menu_structure[] = array
									//~ (
										//~ 'text' => $menu_link, 'classes' => 'folder'
										//~ , 'children' => $this->_list($prm_dbase, $prm_user_id, $prm_menu_module_use, $rows->id, $prm_parent_id, $prm_icon_use, $prm_return_as_array, $prm_as_access_rights, $prm_as_access_rights_checkbox_attr, $prm_as_access_rights_via_ajax)
									//~ )
								//~ : $menu_structure['<span class="folder">'.$menu_link.'</span>'] = $this->_list($prm_dbase, $prm_user_id, $prm_menu_module_use, $rows->id, $prm_parent_id, $prm_icon_use, $prm_return_as_array, $prm_as_access_rights, $prm_as_access_rights_checkbox_attr, $prm_as_access_rights_via_ajax);
						//~ } else
						//~ {
							//~ $menu_structure[$menu_link] = $this->_list($prm_dbase, $prm_user_id, $prm_menu_module_use, $rows->id, $prm_parent_id, $prm_icon_use, $prm_return_as_array, $prm_as_access_rights, $prm_as_access_rights_checkbox_attr, $prm_as_access_rights_via_ajax);
						//~ }
						//~ break;
//~
					//~ case FALSE:
						//~ if ($prm_as_access_rights == TRUE)
						//~ {
							//~ $menu_structure[] = array('text' => $menu_link, 'classes' => 'folder');
						//~ } else
						//~ {
							//~ $menu_structure[$menu_link] = $menu_link;
						//~ }
						//~ break;
				//~ }
			}

			if ($prm_menu_module_use == 'FALSE')
			{
				$menu_structure_new = array();
				foreach ($menu_structure as $key => $val)
				{
					$menu_structure_new = array_merge($menu_structure_new, $val);
				}
				$menu_structure = $menu_structure_new;
			}

		}


		return $menu_structure;
	}


	/**
	 * @function generate_favorite()
	 * @description generate the favorite menu at the desktop
	 */
	function generate_favorite($prm_dbase = 'db_default', $prm_user_id, $prm_icon_use = TRUE, $prm_description_use = FALSE)
	{
		$use_db = $this->{$prm_dbase};

		$sql = 'select c.modules__id as modules_id, c.menus__id, b.name, b.title, concat("<br />", description) as description, link, icon, target'
			. ' from bz_biskitz_menus a, bz_biskitz_menus_lang b, bz_biskitz_user_access c, bz_biskitz_modules d'
			. ' where a.modules__id = b.modules__id and a.modules__id = c.modules__id'
			. ' and a.modules__id = d.id'
			. ' and b.modules__id = c.modules__id'
			. ' and a.id = b.menus__id and a.id = c.menus__id and b.menus__id = c.menus__id'
			. ' and language__id = ? and d.status = ? and biskitz_user__id = ? and c.type = ?';
		$qry = $use_db->query
			(
				$sql
				, array($this->session->userdata('session_user_language_id'), 'Active', $prm_user_id, 'favorite')
			);

		$return_value = array();
		if ($qry->num_rows() > 0)
		{
			$this->load->helper('text');
			/**
			$module_id_prev = $qry->row()->modules_id;
			$module_id_next = $qry->row()->modules_id;
			*/

			foreach ($qry->result() as $rows)
			{
				/**
				$module_id_next = $rows->modules_id;
				if ($module_id_prev != $module_id_next)
				{
					$module_id_prev = $rows->modules_id;
					$return_value[$module_id_prev.$module_id_next] = '<div class="row_new"></div>';
				}
				*/


				/**
				 * @description need image to show ?
				 */
				$menu_image = '';
				if ($prm_icon_use && $rows->icon != NULL)
				{
					$img_attr = array
						(
							'src' => site_url('themes/' . $this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN'] . '/images/menu/32/' . $rows->icon)
							, 'border' => 0
							, 'width' => 32, 'height' => 32
						);
					$menu_image = img($img_attr, TRUE);
				}


				$return_value[$rows->menus__id] = anchor
					(
						$rows->link
						, $menu_image . (($prm_description_use) ? '<br />' . $rows->title : '')
						, array
							(
								'title' => '<b>' . $rows->title . '</b>' . nl2br(word_wrap($rows->description, 40))
								, 'target' => $rows->target
							)
					);
			}

		}
		else
		{
			$return_value = 'Error'; //$this->lang->line('desktop_favorite_error');
		}


		return $return_value;
	}


	/**
	 * @function shows()
	 * @description show the menu
	 */
	function shows($prm_favorite_show = TRUE, $prm_favorite_description = FALSE)
	{
		$return_value = array
			(
				'JAVASCRIPT_MENU' => '<script>'
					. '$(function(){'
					. '$("#multi-ddm, #multi-ddm-notifier").dropDownMenu({timer: 5000, parentMO: "parent-hover", childMO: "child-hover"});'
					. '});</script>'

				, 'PAGE' => array
					(
						'MENU' => array
							(
								'STRUCTURE' => ul
									(
										array_merge
										(
											array
												(
													'biskitZMenu' => '<div>'
														. anchor
															(
																site_url('admin/desktop')
																, '&nbsp;'
																, array('title' => $this->web_data['BISKITZ']['HEADER']['LINKS']['DESKTOP']['TITLE'], 'class' => 'biskitZMenu')
															)
														. '</div>'
												)
											, $this->generate
												(
													'db_default'
													, $this->session->userdata('session_user_id'), $this->session->userdata('session_user_menu_modul_use')
													, ''
													, TRUE, TRUE, FALSE
													, TRUE, ''
													, FALSE, array(), FALSE
													, 0
													, 'Show'
												)
										)
										, array('id' => 'multi-ddm')
									)

								, 'FAVORITE' => ($prm_favorite_show == TRUE)
										? array
											(
												'TITLE' => $this->lang->line('desktop_favorite_title')
												, 'ICON' => 'bookmark_add.png'
												, 'DESC' => $this->lang->line('desktop_favorite_desc')
												, 'LIST' => ul($this->generate_favorite('db_default', $this->session->userdata('session_user_id'), TRUE, $prm_favorite_description))
											)
										: NULL

								, 'ERROR' => $this->lang->line('menu_error')
							)
					)
			);


		return $return_value;
	}


	/**
	 * @function _list_combo()
	 * @description the menu list for the optGroup
	 * @status DEPRECATED
	function _list_combo
		(
			$prm_dbase = 'db_default'
			, $prm_module_id = 1, $prm_parent_id = 0, $prm_level = 0, $prm_separator = '&mdash;'
		)
	{
		$use_db = $this->{$prm_dbase};

		$sql = 'select c.modules__id as modules_id, c.id as menu_id, d.name as name'
			. ' from bz_biskitz_modules a, bz_biskitz_menus c, bz_biskitz_menus_lang d'
			. ' where a.id = c.modules__id'
			. ' and c.modules__id = d.modules__id and c.id = d.menus__id'
			. ' and d.language__id = ?'
			. ' and status = ? and shows = ? and c.modules__id = ? and parent_id = ? order by c.orders';

		 $qry = $use_db->query
			(
				$sql
				, array
					(
						$this->session->userdata('session_user_language_id')
						, 'Active'
						, 'Show'
						, $prm_module_id
						, $prm_parent_id
					)
			);


		if ($qry->num_rows() > 0)
		{
			foreach ($qry->result() as $rows)
			{
				 // @description check if there is any sub menu or not
				$menu_sub_count = $this->M_database->total_rows
					(
						$prm_dbase
						, 'biskitz_menus'
						, array
							(
								'modules__id' => $rows->modules_id
								, 'parent_id' => $rows->menu_id
								, 'shows' => 'Show'
							)
					);

				switch ($menu_sub_count)
				{
					case 0:
						$this->menu_structure_combo .= '<option value="'.$rows->modules_id.';'.$rows->menu_id.'" style="padding-left: ' . ($prm_level * 10) . 'px">' . $prm_separator.$rows->name . '</option>';

						break;

					default:
						$this->menu_structure_combo .= '<optgroup label="'.$prm_separator.$rows->name.'" style="padding-left: ' . ($prm_level * 10) . 'px" class="group_sub_module"></optgroup>';
						break;
				}

				$this->_list_combo($prm_dbase, $rows->modules_id, $rows->menu_id, $prm_level + 1, $prm_separator);
			}
		}
	}
	 */


	/**
	 * @function generate_combo()
	 * @description generate the menu for the optGroup;
	 *							we have to build the <select> manually due to the speed of the form generation
	 * @status DEPRECATED
	function generate_combo
		(
			$prm_dbase = 'db_default'
			, $prm_obj_attr = array(), $prm_parent_id = 0
		)
	{
		$use_db = $this->{$prm_dbase};

		$sql = 'select a.id, a.name'
			. ' from bz_biskitz_modules a, bz_biskitz_menus b'
			. ' where a.id = b.modules__id and status = ?'
			. ' group by a.id order by a.orders, b.orders';

		$qry = $use_db->query
			(
				$sql
				, array
					(
						'Active'
					)
			);

		if ($qry->num_rows() > 0)
		{
			$obj_attr = '';
			foreach ($prm_obj_attr as $obj_key => $obj_value)
			{
				$obj_attr .= $obj_key.'="'.$obj_value.'" ';
			}
			$this->menu_structure_combo .= '<select '.$obj_attr.'multiple="multiple">';
			foreach ($qry->result() as $rows)
			{
				$this->menu_structure_combo .= '<optgroup label="'.$rows->name.'" class="group_module">';
				$this->_list_combo($prm_dbase, $rows->id, $prm_parent_id);
				$this->menu_structure_combo .= '</optgroup>';
			}
			$this->menu_structure_combo .= '</select>';

			return $this->menu_structure_combo;
		}
	}
	 */


	/**
	 * @function valid_check()
	 * @description check the menu, is the menu valid for the user to access for ?
	 */
	function valid_check($prm_dbase = 'db_default', $prm_user_id = '')
	{
		$use_db = $this->{$prm_dbase};

		$sql = 'select type from bz_biskitz_menus a'
			. ' join bz_biskitz_user_access b on a.modules__id = b.modules__id and a.id = b.menus__id and shows != ?'
			. ' and biskitz_user__id = ? and link = ?';
		$qry = $use_db->query
			(
				$sql
				, array('Hide', $prm_user_id, $this->bz_segment['URL'])
			);

		if ($qry->num_rows() > 0)
		{
			$access_rights = $this->M_functions->array_flatten($qry->result_array());

			if (in_array('view', $access_rights))
			{
				return $access_rights;
			}
			else
			{
				$logout_auto = TRUE;
			}
		}
		else
		{
			$logout_auto = TRUE;
		}


		if ($logout_auto == TRUE)
		{
			$this->M_login->_logout($prm_dbase, 'logout: user is trying to access the forbidden menu!');
			die ($this->lang->line('login_access_error') . '<script>location.replace("' . site_url('admin') . '");</script>');
		}
	}


	/**
	 * @function detail()
	 * @description get the detail of the menu, usefull when showing the menu detail in a page as a header
	 */
	function detail($prm_dbase = 'db_default', $prm_breadcrumb_use = FALSE, $prm_char_separate = '&raquo;')
	{
		$use_db = $this->{$prm_dbase};

		$sql = 'select a.modules__id as modules_id, a.id as menu_id, b.name as menu_name, b.title as menu_title, a.link as menu_link, b.description as menu_description, a.icon as menu_icon, a.parent_id as menu_parent_id'
			. ' from bz_biskitz_menus a, bz_biskitz_menus_lang b, bz_biskitz_language c'
			. ' where a.modules__id = b.modules__id and a.id = b.menus__id and b.language__id = c.id'
			. ' and c.id = ? and link = ?';
		$qry = $use_db->query
			(
				$sql
				, array($this->session->userdata('session_user_language_id'), $this->bz_segment['URL'])
			);

		if ($qry->num_rows() > 0)
		{
			/**
			 * @description use the breadcrumb ?
			 */
			if ($prm_breadcrumb_use)
			{
				$use_db->select('name as modules_name')->from('biskitz_modules')->where(array('id' => $qry->row()->modules_id));
				$qry_module_name = $use_db->get();
				$breadcrumb = $qry_module_name->row()->modules_name;

				$this->breadcrumb[] = '&nbsp;' . $prm_char_separate . '&nbsp;' . $qry->row()->menu_name;
				$this->_breadcrumb_generate($prm_dbase, $qry->row()->modules_id, $qry->row()->menu_parent_id, $prm_char_separate);

				krsort($this->breadcrumb);
				foreach ($this->breadcrumb as $val)
				{
					$breadcrumb .= $val;
				}
			}
			else
			{
				$breadcrumb = '';
			}


			$this->load->helper('text');

			$return_value = array
				(
					'ID' => array('MODULE' => $qry->row()->modules_id, 'MENU' => $qry->row()->menu_id)
					, 'NAME' => $qry->row()->menu_name
					, 'TITLE' => $qry->row()->menu_title
					, 'DESC' => nl2br(word_wrap($qry->row()->menu_description, 40))
					, 'ICON' => $qry->row()->menu_icon
					, 'BREADCRUMB' => $breadcrumb
				);
		}
		else
		{
			$return_value = array('ID' => array('MODULE' => NULL, 'MENU' => NULL));
		}


		return $return_value;
	}



}

/** End of file m_menu.php */
/** Location: ./biskitz_mpc/biskitz/models/admin/m_menu.php */
